package com.hxk.demo.task;

import com.hxk.demo.service.EcgServiceI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author lyl
 */
@Slf4j
@Service
@EnableAsync
public class AccessTokenTask {

    @Resource
    private EcgServiceI ecgServiceI;

    /**
     * 定时获取accessToken（每一个半小时执行一次）
     * (1.30，4.30，7.30...执行)
     */
    @Scheduled(cron = "0 30 1/3 * * ?")
    @PostConstruct
    @Async
    public void run() {
        log.info("定时获取accessToken开始");
        ecgServiceI.getAccessToken();
        log.info("定时获取accessToken结束");
    }
}
